package com.dongdongshop.testcontroller;

import com.dongdongshop.util.CookieUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.CookieHandler;

/**
 * @Description
 * @ClassName TestCookieController
 * @Author RC
 * @date 2020.12.21 13:22
 */
@Controller
public class TestCookieController {

    @RequestMapping("setCookie")
    @ResponseBody
    public String setCookie(HttpServletRequest request, HttpServletResponse response){
        CookieUtils.setCookie(request,response,"myCookie","helloCookie",1000 * 60 * 30,"utf-8");
        return "set ok";
    }

    @RequestMapping("getCookie")
    @ResponseBody
    public String getCookie(HttpServletRequest request){
        String myCookie = CookieUtils.getCookieValue(request, "myCookie");
        return myCookie;
    }
}
